#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sqlite3


class db(object):
    """
    数据库类
    """

    def __init__(self, dbpath):
        if dbpath == '':
            exit('不能为空！')

        try:
            self.conn = sqlite3.connect(dbpath)
        except IOError:
            print "连接数据库失败！"

    def connectDB(self):
        """
        连接数据库
        :return:
        """
        # print '开始连接数据库'
        self.conn.text_factory = str
        return self.conn.cursor()

    def closeDB(self):
        """
        关闭数据库
        :return:
        """
        print '关闭数据库连接'
        self.conn.commit()
        self.conn.close()
